package com.example.demo.demos.aop;

import com.example.demo.demos.annotation.TESTANO;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @Author: lixz
 * @Date: 2024/11/13/16:15
 */
@Component
@Aspect
public class AOPTest {

    @AfterReturning(value = "@annotation(com.example.demo.demos.annotation.TESTANO)")
    public String testAop(JoinPoint JoinPoint) {
        MethodSignature signature = (MethodSignature) JoinPoint.getSignature();
        Method method = signature.getMethod();
        TESTANO annotation = method.getAnnotation(TESTANO.class);
        String value = annotation.value();
        System.out.println(value);
        return value;
    }
}
